import request from '../index'
import { goodsState } from '@/enum'

export function getGoodsList(index: number, size: number, state?: number) {
  return request.get('/goods', {
    index,
    size,
    state: state !== undefined ? state : null
  })
}

export function getAuditGoodsList(index: number, size: number) {
  return request.get('/goods', {
    index,
    size,
    state: goodsState['待审核']
  })
}

export function pass(id: string) {
  return request.put('/goods', {
    id,
    state: goodsState['发布中']
  })
}

export function noPass(id: string) {
  return request.put('/goods', {
    id,
    state: goodsState['未通过']
  })
}

export function delGoods(id: string) {
  return request.delete('/goods', {
    id
  })
}

export function editGoods(data: {id: string, show?: boolean, sort?: number}) {
  return request.put('/goods', data)
}

export function getCategories() {
  return request.get('/category')
}

export function delCategory(id: string) {
  return request.delete('/category', {
    id
  })
}

export function addCategory(data: {name: string, icon: string, parentId?: string}) {
  return request.post('/category', data)
}

export function editCategory(data: {name: string, icon: string, id: string}) {
  return request.put('/category', data)
}